
<script language="javascript">
function btnSave_onclick(){
	
	return true;
}
</script>

<? $errMsg =''?>
<?

if (isset($_POST['btnSave'])){
	$code          = isset($_POST['txtCode']) ? trim($_POST['txtCode']) : '';
	$name          = isset($_POST['txtName']) ? trim($_POST['txtName']) : '';
	
	if ($name=="") $errMsg .= "Hãy nhập tên danh mục !<br>";
	
	//echo $errMsg;
	//exit;
	if ($errMsg==''){
		if (!empty($_POST['id'])){
			$oldid = $_POST['id'];
			$sql = "update tbl_theloai set code='".$code."',tentheloai='".$name."' where id=".$oldid;
		}else{
			$sql = "insert into tbl_theloai (code, tentheloai) values ('".$code."','".$name."')";
		}
		echo $sql;
		//mysql_query($sql,$conn);
		
		if (mysql_query($sql,$conn)){
				echo '<script>window.location="./?act=doc_cat&cat='.$_REQUEST['cat'].'&page='.$_REQUEST['page'].'&code=1"</script>';
			}else{
				$errMsg = "Không thể cập nhật !";
		}
	}

	
		
}else{
	if (isset($_GET['id'])){
		$oldid=$_GET['id'];
		$page = $_GET['page'];
		$sql = "select * from tbl_theloai where id=".$oldid;
		if ($result = mysql_query($sql,$conn)) {
			$row=mysql_fetch_array($result);
			$code          = $row['code'];
			$name          = $row['tentheloai'];			
		}
	}
}

?>


<form method="post" name="frmForm" enctype="multipart/form-data" action="./">

<input type="hidden" name="act" value="doc_cat_m">
<input type="hidden" name="id" value="<?=$_REQUEST['id']?>">
<input type="hidden" name="page" value="<?=$_REQUEST['page']?>">
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#0069A8" width="100%">
	<tr>
    	<td width="45%">
    		<table border="0" cellpadding="2" bordercolor="#111111" width="100%" cellspacing="0">
				<tr><td height="10"></td></tr>
				<!--<tr>
					<td colspan="3" align="center">
						<table width="100%">
							<? if($image!='' || $image_large!=''){?>
							<tr>
								<td width="15%"></td>
								<td width="40%" align="center" class="smallfont">
<? if ($image!=''){ echo '<img border="0" src="../'.$image.'"><br><br>Hình (kích thước nhỏ)';}?>
								</td>
								
								<td width="40%" align="center" class="smallfont">
<? if ($image_large!=''){ echo '<img border="0" src="../'.$image_large.'"><br><br>Hình (kích thước lớn)';}?>
								</td>
								<td width="15%"></td>
							</tr>
							<? }else{echo '<tr><td colspan="3" class="smallfont" align="center">Chưa có hình ảnh !</td></tr>';}?>
							<tr><td colspan="4" height="10"></td></tr>
							<tr><td colspan="4" height="1" bgcolor="#999999"></td></tr>
							<tr><td colspan="4" height="10"></td></tr>
						</table>
					</td>
				</tr>-->
        		
				
				
				<tr>
        			<td width="15%" class="smallfont" align="right">Mã danh mục</td>
        			<td width="1%" class="smallfont" align="center"></td>
        			<td width="83%" class="smallfont">
						<input value="<?=$code?>" type="text" name="txtCode" class="textbox" size="34">
					</td>
      			</tr>
				
				<tr>
					<td width="15%" class="smallfont" align="right">Tên danh mục</td>
					<td width="1%" class="smallfont" align="center"><font color="#FF0000">*</font></td>
					<td width="83%" class="smallfont">
						<input value="<?=$name?>" type="text" name="txtName" class="textbox" size="34">
					</td>
				</tr>
				
				
				<tr>
					<td width="15%" class="smallfont"></td>
					<td width="1%" class="smallfont" align="center"></td>
					<td width="83%" class="smallfont">
						<input type="submit" name="btnSave" VALUE="Cập nhật" class=button onclick="return btnSave_onclick()">
						<input type="reset" class=button value="Nhập lại">
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
<? if($errMsg!=''){echo '<p align=center class="err">'.$errMsg.'<br></p>';}?>